var toNext;

function validate()
{
   var xmlHttp = new XMLHttpRequest();
   if (xmlHttp==null)
   {
   alert ("Your browser does not support AJAX!");
   return;
   }

   var str = document.getElementById("newuniversity").value;
   var url = "universityValidate.jsp";
   url = url + "?university=" + str;   
   
   var responseHandler = function()
   {
      if(xmlHttp.readyState==4)
         {
    	    toNext = (xmlHttp.responseText).trim();
    		if(toNext == "true"){
    			alert("University has already existed above!");
    		}
    		else{
    			if(document.getElementById("newuniversity").value != ""){
    				document.getElementById("myform").submit();
    			}
    		}
         }
   };
   xmlHttp.onreadystatechange = responseHandler;
   
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);

   return false;
}
